package concurrency

import (
	"fmt"
	"sync/atomic"
)

func main() {
	var num int64
	num = 1
	//									old 1 和 旧值一样，替换成功
	ok := atomic.CompareAndSwapInt64(&num, 1, 10)
	fmt.Println("ok =", ok)
	fmt.Println("num =", num)

	//									old 2 和 旧值不一样，替换失败
	ok = atomic.CompareAndSwapInt64(&num, 2, 20)
	fmt.Println("ok =", ok)
	fmt.Println("num =", num)
}
